﻿
var BookList=function (ref){
    this.cite=$class.call(ref,"dfn","favorite");
    if(!this.cite)return;
    
    this.autor=$a.call(this.cite,"a");
    this.img=$a.call(this.cite,"img");
    
    var _this=this;
    this.autor.onclick=function(){
        _this.clickHander();
        return false;
    }
    
    //ref.onmouseover=Delegate.create(this,this.overHander);
    //ref.onmouseout=Delegate.create(this,this.outHander);
}
BookList.prototype.overHander=function(){
    this.cite.style.display="block";
}
BookList.prototype.outHander=function(){
    this.cite.style.display="none";
}

BookList.prototype.clickHander=function(){
        this.xmlReq=new ajax.$x(this.autor.href,"GET",this.returnFunction,null,"",this,false);
       // return false;
}
BookList.prototype.returnFunction=function(){
    var message=this.req.responseXML.firstChild.firstChild.firstChild.nodeValue;
    alert(message);
    
    var s=this.relate.img.src;
    var url=this.relate.autor.href;
    if(s.indexOf("note_new")>0){
        s=s.replace("note_new","note_delete");
        url=url.replace("type=add","type=del");
    }else{
        s=s.replace("note_delete","note_new");
        url=url.replace("type=del","type=add");
    }
    this.relate.img.src=s;
    this.relate.autor.href=url;
    
}


function initBookList(){
    var bookList=new Array;
    if(!$("booklist"))return;
    
    //是否在首页上,如是,应用类型来取得booklist,因为存在多个,用id只取一个.
    if($("divHanger")){
        var mainContent=$("maincontent");
        bookList=$classs.call(mainContent,"ul","booklist");
    }else{
        bookList.push($("booklist"));
    }
    for(var i=0;i<bookList.length;i++){
        var athors=$as.call(bookList[i],"li");
        var len=athors.length;
        for(var j=0;j<len;j++){
           new BookList(athors[j]);
        }
     }
}

addLoadEvent(initBookList);